package com.ylbh.modules.eggupgrade.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.member.vo.MemberVO;
import com.ylbh.common.utils.*;
import com.ylbh.modules.member.service.MemberService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ylbh.modules.eggupgrade.entity.ShoppingEggUpgradeSetting;
import com.ylbh.modules.eggupgrade.service.ShoppingEggUpgradeSettingService;


/**
 * 彩蛋邀请升级配置信息
 *
 * @author czx
 * @date 2020-01-07 17:53:13
 */
@RestController
@RequestMapping("eggUpgrade")
public class ShoppingEggUpgradeSettingController {

    @Autowired
    private ShoppingEggUpgradeSettingService shoppingEggUpgradeSettingService;

    @Autowired
    private MemberService memberService;

    @ApiOperation("彩蛋邀请升级配置信息列表")
    @GetMapping("/queryEggUpgradeList")
    @RequiresPermissions("eggUpgrade:list")
    public CommonResult queryEggUpgradeList(PageDTO pageDTO){
        PageUtils page = shoppingEggUpgradeSettingService.queryEggUpgradeList(pageDTO);
        return Ref.ok(page);
    }


    @ApiOperation("彩蛋邀请升级配置信息详情")
    @GetMapping("/getEggUpgradeInfoId/{id}")
    @RequiresPermissions("eggUpgrade:info")
    public CommonResult getEggUpgradeInfoId(@PathVariable("id") String id){
		ShoppingEggUpgradeSetting shoppingEggUpgradeSetting = shoppingEggUpgradeSettingService.getById(id);
        return Ref.ok(shoppingEggUpgradeSetting);
    }

    @SysLog("新增彩蛋邀请升级配置信息")
    @ApiOperation("新增彩蛋邀请升级配置信息")
    @PostMapping("/addEggUpgrade")
    @RequiresPermissions("eggUpgrade:save")
    public CommonResult addEggUpgrade(@RequestBody ShoppingEggUpgradeSetting shoppingEggUpgradeSetting){
        shoppingEggUpgradeSetting.setId(new IdWorker().nextId());
        shoppingEggUpgradeSetting.setCreateTime(new Date());
        shoppingEggUpgradeSetting.setSysUserId(ShiroUtils.getUserId().toString());
        shoppingEggUpgradeSetting.setRecommendUserType(7);
		shoppingEggUpgradeSettingService.addEggUpgrade(shoppingEggUpgradeSetting);
        return Ref.ok();
    }

    @SysLog("修改彩蛋邀请升级配置信息")
    @ApiOperation("修改彩蛋邀请升级配置信息")
    @PostMapping("/modifyEggUpgradeById")
    @RequiresPermissions("eggUpgrade:update")
    public CommonResult modifyEggUpgradeById(@RequestBody ShoppingEggUpgradeSetting shoppingEggUpgradeSetting){
        shoppingEggUpgradeSetting.setSysUserId(ShiroUtils.getUserId().toString());
		shoppingEggUpgradeSettingService.updateById(shoppingEggUpgradeSetting);
        return Ref.ok();
    }

    @SysLog("删除彩蛋邀请升级配置信息")
    @ApiOperation("删除彩蛋邀请升级配置信息")
    @PostMapping("/removeEggUpgradeByIds")
    @RequiresPermissions("eggUpgrade:delete")
    public CommonResult removeEggUpgradeByIds(@RequestBody String[] ids){
		shoppingEggUpgradeSettingService.removeEggUpgradeByIds(Arrays.asList(ids));
        return Ref.ok();
    }

    @SysLog("彩蛋邀请升级配置开启状态")
    @ApiOperation("彩蛋邀请升级配置开启状态")
    @PostMapping("modifyEggUpgradeStateById/{id}/{state}")
    @RequiresPermissions("eggUpgrade:state")
    public CommonResult modifyEggUpgradeStateById(@PathVariable String id, @PathVariable Integer state) {
        shoppingEggUpgradeSettingService.modifyEggUpgradeStateById(id, state);
        return Ref.ok();
    }

    @ApiOperation("查询出所有的合伙人")
    @GetMapping("queryAllPartnerList")
    public CommonResult queryAllPartnerList() {
        List<MemberVO> list = memberService.queryAllPartnerList();
        return Ref.ok(list);
    }

}
